Skip to content

Release/v1.1.0#3

Merged
otapiero merged 6 commits intomainfrom
release/v1.1.0
Mar 6, 2026
Merged

Release/v1.1.0#3
otapiero merged 6 commits intomainfrom
release/v1.1.0

Conversation

@otapiero
Copy link
Copy Markdown
Collaborator

@otapiero otapiero commented Mar 6, 2026

Add IRequestContextPropagator for simplified context propagation
Introduce a new interface, IRequestContextPropagator<T>, to streamline non-HTTP context propagation, replacing a manual three-step process with a more efficient using block. Enhance validation support for typed request contexts using DataAnnotations and improve related classes. Clean up unnecessary using directives and simplify class constructors.

claude and others added 4 commits March 5, 2026 16:34
…tion

Introduces a single interface that combines deserialization and accessor
management into one scoped operation, replacing the manual three-step pattern
(deserialize → set accessor → finally clear) with a simple using block:

    using var _ = propagator.Propagate(metadata);
    // context accessible via DI or accessor.GetRequired<T>()

Changes:
- Add IRequestContextPropagator<T> interface (Abstractions/)
- Add RequestContextPropagator<T> implementation (Infrastructure/)
- Register IRequestContextPropagator<> as open-generic singleton in AddTypedRequestContextPropagation()
- Add unit tests covering: context set during scope, cleared after dispose,
  cleared even when handler throws, and exception on missing required keys

https://claude.ai/code/session_0123zepdZJiUTyc6XLLezZCv
@otapiero otapiero requested a review from Copilot March 6, 2026 12:22
@otapiero otapiero self-assigned this Mar 6, 2026
@otapiero otapiero added the enhancement New feature or request label Mar 6, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces first-class request-context validation (defaulting to DataAnnotations) and a new propagator abstraction to simplify context activation for non-HTTP flows, while refactoring context lifetime management into a reusable scope factory.

Changes:

  • Add validation infrastructure (IRequestContextValidator<T>, RequestContextValidationException, default DataAnnotations validator) and wire it into middleware and registration.
  • Introduce IRequestContextPropagator<T> + implementation to combine deserialization + accessor lifecycle in a single using scope for non-HTTP flows.
  • Refactor accessor lifecycle management into RequestContextScopeFactory / RequestContextScope, plus cleanup of redundant using directives.

Reviewed changes

Copilot reviewed 27 out of 28 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/TypedRequestContext.UnitTests/RequestContextValidationTests.cs Adds unit coverage for DataAnnotations validation and scope factory validation behavior.
tests/TypedRequestContext.Propagation.UnitTests/PropagationTests.cs Adds unit coverage for the new IRequestContextPropagator<T> behavior.
tests/TypedRequestContext.AspNetCore.IntegrationTests/RequestContextMiddlewareIntegrationTests.cs Adds integration coverage for HTTP validation failures (400 + structured errors).
src/TypedRequestContext/TypedRequestContext.csproj Adds InternalsVisibleTo for propagation and unit test assemblies.
src/TypedRequestContext/Middleware/RequestContextServiceCollectionExtensions.cs Registers RequestContextScopeFactory and validator services; tracks validator mappings in options.
src/TypedRequestContext/Middleware/RequestContextMiddleware.cs Uses scope factory to manage accessor state; returns structured 400 responses on validation failures.
src/TypedRequestContext/Middleware/RequestContextEndpointExtensions.cs Removes redundant using.
src/TypedRequestContext/Infrastructure/RequestContextValidationException.cs Adds a dedicated exception type for validation failures.
src/TypedRequestContext/Infrastructure/RequestContextScopeFactory.cs Adds centralized context activation + validation + scope creation logic.
src/TypedRequestContext/Infrastructure/RequestContextScope.cs Adds nested-scope support to restore previous context on dispose.
src/TypedRequestContext/Infrastructure/RequestContextBuilder.cs Adds fluent configuration for enabling validation and custom validators.
src/TypedRequestContext/Infrastructure/RequestContextAccessor.cs Removes redundant using.
src/TypedRequestContext/Infrastructure/PropertyMapper.cs Removes redundant using.
src/TypedRequestContext/Infrastructure/DataAnnotationsRequestContextValidator.cs Adds default validator implementation using System.ComponentModel.DataAnnotations.
src/TypedRequestContext/Infrastructure/CorrelationContext.cs Removes redundant using.
src/TypedRequestContext/Infrastructure/AttributeBasedRequestContextExtractor.cs Removes redundant using.
src/TypedRequestContext/Abstractions/RequestContextValidationError.cs Adds a structured validation error record.
src/TypedRequestContext/Abstractions/IRequestContextValidator.cs Adds validator abstraction for typed request contexts.
src/TypedRequestContext.Propagation/Infrastructure/RequestContextPropagator.cs Adds default propagator implementation using deserializer + scope factory.
src/TypedRequestContext.Propagation/Infrastructure/PropagationHeadersProvider.cs Refactors constructor to primary-constructor style; preserves serialization behavior.
src/TypedRequestContext.Propagation/Infrastructure/AttributeBasedRequestContextSerializer.cs Removes redundant using.
src/TypedRequestContext.Propagation/Infrastructure/AttributeBasedRequestContextDeserializer.cs Removes redundant using.
src/TypedRequestContext.Propagation/DependencyInjection/TypedRequestContextPropagationServiceCollectionExtensions.cs Registers IRequestContextPropagator<>.
src/TypedRequestContext.Propagation/Abstractions/IRequestContextSerializer.cs Removes redundant using.
src/TypedRequestContext.Propagation/Abstractions/IRequestContextPropagator.cs Adds new propagator abstraction with overload for scoped validator dependencies.
src/TypedRequestContext.Propagation/Abstractions/IRequestContextDeserializer.cs Removes redundant using.
.gitignore Ignores .claude/settings.local.json.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…nException.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@otapiero otapiero merged commit fa2a1e1 into main Mar 6, 2026
1 check passed
@otapiero otapiero deleted the release/v1.1.0 branch March 8, 2026 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants